﻿using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Model
{
	public class TeacherInfoConfig : IEntityTypeConfiguration<TeacherInfo>
	{
		public void Configure(EntityTypeBuilder<TeacherInfo> builder)
		{
			builder.ToTable("T_Teacher");
			builder.Property(t => t.UserName).HasMaxLength(20).IsRequired();
			builder.Property(t => t.Password).HasMaxLength(20).IsRequired();
			builder.Property(t => t.FullName).HasMaxLength(20).IsRequired();
			builder.Property(t => t.Phone).HasMaxLength(13).IsRequired();
			builder.Property(t => t.DelFlag).HasMaxLength(1).HasDefaultValue(0);
			builder.Property(t => t.Role).HasMaxLength(1).IsRequired();
			builder.Property(t => t.TeaNum).HasMaxLength(20).IsRequired();

			builder.HasMany<CourseInfo>(a => a.CourseList).WithOne(a => a.Teachers);
			builder.HasIndex(t=>t.UserName).IsUnique();
			builder.HasIndex(t=>t.TeaNum).IsUnique();
		}
	}
}
